import axios from "../utils/http";

export const getCartList = ()=>{
    const userinfo = JSON.parse(localStorage.getItem("loginData")||'{}')
    return axios.get("/cartlist?uid="+userinfo.uid)
}

//循环后端接口返回的数据，整理为数组格式 [{content: []},{content: []},] ==> [a,b,c]
export const takeCartList = (cartList)=>{
    let clist = []
    cartList.forEach(element=>{
        if(element.content){
            element.content.forEach(obj=>{ //obj就是每条数据
                obj.checked = false //手动的设置itme选中属性
                clist.push(obj)
            })
        }
    })
    return clist //这里返回的就是carts当中使用的cartList
}

export const cartCount = (cartList)=>{
    let length = 0;
    cartList.forEach(element => {
        if(element.content){
            element.content.forEach(obj=>{
                length += 1
            })
        }
    });
    return length
}

